<%--suppress JSJQueryEfficiency --%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css"
          href="../../../js/jquery-easyui-1.9.5/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"
          href="../../../js/jquery-easyui-1.9.5/themes/icon.css">
    <link rel="stylesheet" type="text/css"
          href="../../../js/jquery-easyui-1.9.5/themes/color.css">
    <script type="text/javascript"
            src="../../../js/jquery-easyui-1.9.5/jquery.min.js"></script>
    <script type="text/javascript"
            src="../../../js/jquery-easyui-1.9.5/jquery.easyui.min.js"></script>
</head>
<body>
<table id="volunteerMessage_dg" title="义工信息" class="easyui-datagrid" style="width:100%;height:100%"
       url="../volunteerMessage/list"
       toolbar="#volunteerMessage_toolbar"
       rownumbers="true" pagination="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="volunteerNo" style="width: 14%">义工编号</th>
        <th field="name" style="width: 14%">义工姓名账号</th>
        <th field="password" style="width: 14%">密码</th>
        <th field="volunteerSex" style="width: 14%">性别</th>
        <th field="volunteerTime" style="width: 14%">义工时长</th>
        <th field="volunteerNum" style="width: 14%">服务次数</th>
        <th field="dept" formatter="deptFormatter" style="width: 14%">所属部门</th>
    </tr>
    </thead>
</table>

<div id="volunteerMessage_toolbar">
    <label for="searchNameVolunteerMessage">义工姓名账号:</label>
    <input id="searchNameVolunteerMessage" name="name" type="text" class="easyui-textbox"/>
    <label for="searchDeptVolunteerMessage">部门编号:</label>
    <input id="searchDeptVolunteerMessage" name="dept.deptNo"
           class="easyui-combobox" data-options="valueField:'deptNo',textField:'deptName',
                   url:'../volunteerMessage/deptList'">
    <a id="search" href="javascript:doVolunteerMessageSearch();" class="easyui-linkbutton"
       data-options="iconCls:'icon-search'">Search</a>
    <a id="reset" href="javascript:doVolunteerMessageReset();" class="easyui-linkbutton"
       data-options="iconCls:'icon-redo'">Reset</a>
    <br/>
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
       onclick="newVolunteerMessage()">New volunteerMessage</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true"
       onclick="editVolunteerMessage()">Edit volunteerMessage</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
       onclick="destroyVolunteerMessage()">Remove volunteerMessage</a>
</div>

<%--        新增和修改对话框--%>
<div id="volunteerMessage_dlg" class="easyui-dialog" style="width:400px;height:500px;padding:10px 20px"
     closed="true" buttons="#volunteerMessage_dlg-buttons">
    <div class="ftitle" style="text-align: center">volunteer Message</div>
    <br>
    <form id="volunteerMessage_fm" method="post">
        <div class="fitem">
            <label for="name">义工账号&emsp;</label>
            <input id="name" name="name" class="easyui-textbox"
                   data-options="required:true,missingMessage:'name is not null'"
                   prompt="name" style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="password">密&emsp;&emsp;码&emsp;</label>
            <input id="password" name="password" class="easyui-passwordbox"
                   data-options="required:true,missingMessage:'password is not null'"
                   prompt="password" style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="volunteerSex">性&emsp;&emsp;别&emsp;</label>
            <input id="volunteerSex" name="volunteerSex" class="easyui-textbox"
                   data-options="required:true,missingMessage:'volunteerSex is not null'"
                   prompt="volunteerSex" style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="volunteerTime">义工时长&emsp;</label>
            <input id="volunteerTime" name="volunteerTime" class="easyui-textbox"
                   prompt="volunteerTime" style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="volunteerNum">服务次数&emsp;</label>
            <input id="volunteerNum" name="volunteerNum" class="easyui-textbox"
                   prompt="volunteerNum" style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="dept">所属部门&emsp;</label>
            <input id="dept" name="dept.deptNo" class="easyui-combobox"
                   data-options="required:true,missingMessage:'deptNo is not null',
                           valueField:'deptNo',textField:'deptName',url:'../volunteerMessage/deptList'"
                   style="width: 250px">
        </div>
    </form>
</div>

<div id="volunteerMessage_dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok"
       onclick="saveVolunteerMessage()">Save</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel"
       onclick="$('#volunteerMessage_dlg').dialog('close')">Cancel</a>
</div>

<script type="text/javascript">
    function deptFormatter(value) {
        return value.deptName;
    }

    function doVolunteerMessageSearch() {
        $("#searchNameVolunteerMessage").textbox('setValue', $("#searchNameVolunteerMessage").val().trim());
        //调用datagrid对象的load方法查询数据，并传递查询参数
        $("#volunteerMessage_dg").datagrid("load", {
            "name": $("#searchNameVolunteerMessage").val(),
            "dept.deptNo": $("#searchDeptVolunteerMessage").val()
        });
    }

    function doVolunteerMessageReset() {
        $("#searchNameVolunteerMessage").textbox('setValue', '');
        $("#searchDeptVolunteerMessage").combobox('clear');
        //清空查询参数后，重新加载数据
        $("#volunteerMessage_dg").datagrid("load", {});
    }

    function loadDeptSuccess(value) {
        $('#dept').combobox({
            onLoadSuccess: function (data) {
                if (data) {
                    if (value) {
                        $('#dept').combobox('select', value);
                    } else {
                        $('#dept').combobox('select', data[0].deptNo);
                    }
                }
            }
        });
    }

    function newVolunteerMessage() {
        $('#volunteerMessage_dlg').dialog('open').dialog('setTitle', 'New volunteerMessage');
        $('#volunteerMessage_fm').form('clear');
        url = '../volunteerMessage/add';
        loadDeptSuccess();
    }

    function editVolunteerMessage() {
        $('#volunteerMessage_fm').form('clear');
        var row = $('#volunteerMessage_dg').datagrid('getSelected');
        if (row) {
            $('#volunteerMessage_dlg').dialog('open').dialog('setTitle', 'Edit volunteerMessage');
            $('#volunteerMessage_fm').form('load', row);
            url = '../volunteerMessage/edit?volunteerNo=' + row.volunteerNo;
            loadDeptSuccess(row.dept.deptNo);
        } else {
            $.messager.show({
                title: 'Error',
                msg: "请选择要修改的用户信息"
            });
        }
    }

    function destroyVolunteerMessage() {
        var row = $('#volunteerMessage_dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('Confirm', '是否需要删除该信息？', function (r) {
                if (r) {
                    $.post('../volunteerMessage/delete', {volunteerNo: row.volunteerNo}, function (result) {
                        if (result.success) {
                            $('#volunteerMessage_dg').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.show({
                title: 'Error',
                msg: "请选择要删除的用户信息"
            });
        }
    }

    function saveVolunteerMessage() {
        $('#volunteerMessage_fm').form('submit', {
            url: url,
            onSubmit: function () {
                // 提交表单前 表单验证
                return $(this).form('validate');
            },
            success: function (result) {
                // 收到服务器响应的json字符串后，调用这里的代码，回调函数当浏览器收到服务器返回的数据后才执行
                var result = eval('(' + result + ')');
                if (!result.success) {
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                } else {
                    $('#volunteerMessage_dlg').dialog('close');		// 新增成功，关闭对话框
                    $('#volunteerMessage_dg').datagrid('reload');	// 新增成功，刷新列表数据
                }
            }
        });
    }
</script>
</body>
</html>
